<h1>
    <?=$this->title ?>
</h1>
<?
    if (!$this->is_add) // Edit Mode
    {
?>
<div id="right_menu">
    <ul>
<?
        $i = 0;
        foreach($this->menu as $title => $action)
        {
            $i++;
            $container = ($action == 'edit' || $action == 'delete') ? 'inner' : 'container';
?>
        <li
<?
            if (count($this->menu) == $i)
                echo "class=\"last\"";
            
            if ($this->action == $action)
                echo "class=\"active\"";
?>
            >

            <a href="#"
<?
            if ($action == 'delete')
            {
?>
                onClick="if(confirm('Sure?')) {ajaxTypes({id: <?=$this->model_type->getID(); ?>,
                                                                action: '<?=$action ?>',
                                                                container: '<?=$container ?>'}); return false;};"
<?
            }
            else
            {
?>
                onClick="ajaxTypes({id: <?=$this->model_type->getID(); ?>,
                                          action: '<?=$action ?>',
                                          container: '<?=$container ?>',
                                          no_apply: true}); return false;"
<?
            }
?>              ><?=$title ?></a>
	</li>
<?
        };
?>
	</ul>
</div>
<?
    }; //if (!$this->is_add)
?>
<div id="container" <? if ($this->is_add) echo "style=\"margin-top: -50px;\""; ?>>
    <div>
<?
    Principio_Library_Common::printErrorsAndMsg();
?>
        <table class="form_table">
            <tr>
                <td class="title">Type:</td>
                <td class="input_field">
                    <input type="text" name="type" id="type" value="<?=$this->model_type->getType(); ?>" />
                </td>
            </tr>
            <tr>
                <td class="title">Caption:</td>
                <td class="input_field">
                    <input type="text" name="caption" id="caption" value="<?=$this->model_type->getCaption(); ?>" />
                </td>
            </tr>
            <tr>
                <td class="title">Exts:</td>
                <td class="input_field">
<?
    if ($this->is_add)
    {
?>
                        <select name="exts" id="exts">
<?
        for ($i = 1; $i <= 6; $i++)
        {
?>
                            <option value="<?=$i ?>" <? if ($this->spa_type_data['exts'] == $i) echo " selected "; ?> ><?=$i ?></option>
<?
        };
?>
                        </select>
<?
        }
        else
        {
?>
                        <input type="text" id="exts" disabled value="<?=$this->model_type->getExts(); ?>" />
<?
        };
?>
                </td>
            </tr>
            <tr>
                <td class="title">Firmware:</td>
                <td class="input_field">
                    <select name="firmware_id" id="firmware_id">
                       <option value="-1">No firmware (disable firmware upgrade)</option>
<?
        foreach ($this->firmwares as $model_firmware)
        {
?>
                        <option value="<?=$model_firmware->getID() ?>" <? if ($this->model_type->getModelFirmware()->getID() == $model_firmware->getID()) echo " selected "; ?>><?=$model_firmware->getCaption() ?> [Version: <?=$model_firmware->getVersion() ?>]</option>
<?
        };
?>
                    </select>
                </td>
            </tr>
        </table>
 	    <table border="0" width="100%" class="buttons">
            <tr>
                <td align="right">
                    <input class="save" type="submit" name="apply" value="<?=($this->is_add ? "Add type" : "Apply changes") ?>"
                           onClick="ajaxTypes({id: <?=($this->is_add ? "" : $this->model_type->getID()) ?>, action: '<?=$this->action ?>', container: 'inner'})"/>
                    <input class="cancel" type="submit" name="reset" value="Reset" onClick="<?=($this->is_add ? "addItem({menu: 'types', container: 'inner'})" : "ajaxTypes({id: ".$this->model_type->getID().", action: 'edit', container: 'inner', no_apply: true})") ?>;"/>
                </td>
            </tr>
        </table>
    </div>
</div>
